﻿#region zh-CHS 2006 - 2008 DemoSoft 团队 | en 2006 - 2008 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2008 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Runtime.InteropServices;
using Demo.Mmose.Core.Common;
#endregion

namespace Demo.Mmose.Misc.Net.Dll
{
    /// <summary>
    /// 客户端的句柄
    /// </summary>
    [MultiThreadedSupport( "zh-CHS", "当前的类所有成员都可锁定,支持多线程操作" )]
    public class ConnectHandle
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 客户端的句柄指针
        /// </summary>
        private IntPtr m_Value                                                  = IntPtr.Zero;
        /// <summary>
        /// 客户端的管理句柄
        /// </summary>
        private ConnectHandleManager m_SocketHandlerManager          = null;
        #endregion

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 初始化构造
        /// </summary>
        public ConnectHandle()
        {
        }
        #endregion

        #region zh-CHS 共有属性 | en Public Properties
        /// <summary>
        /// 客户端的管理句柄
        /// </summary>
        public ConnectHandleManager SocketHandlerManager
        {
            get { return m_SocketHandlerManager; }
            set { m_SocketHandlerManager = value; }
        }

        /// <summary>
        /// 客户端是否在线
        /// </summary>
        public bool IsOnline
        {
            get { return ConnectHandle.ConnectHandle_IsOnline( m_Value ); }
        }

        /// <summary>
        /// 远程的端口
        /// </summary>
        public int RemotePort
        {
            get { return ConnectHandle.ConnectHandle_RemotePort( m_Value ); }
        }

        /// <summary>
        /// 第一次数据包的时间
        /// </summary>
        public long FirstTime
        {
            get { return ConnectHandle.ConnectHandle_FirstTime( m_Value ); }
        }

        /// <summary>
        /// 远程地址
        /// </summary>
        public string RemoteOnlyIP
        {
            get { return ConnectHandle.ConnectHandle_RemoteOnlyIP( m_Value ); }
        }

        /// <summary>
        /// 在线时间
        /// </summary>
        public long OnlineTime
        {
            get { return ConnectHandle.ConnectHandle_OnlineTime( m_Value ); }
        }

        /// <summary>
        /// 服务端的地址和端口
        /// </summary>
        public string ServerAddress
        {
            get { return ConnectHandle.ConnectHandle_ServerAddress( m_Value ); }
        }

        /// <summary>
        /// 数据包的总数量
        /// </summary>
        public long MessageBlockNumbers
        {
            get { return ConnectHandle.ConnectHandle_MessageBlockNumbers( m_Value ); }
        }

        /// <summary>
        /// 60秒内的数据包的数量
        /// </summary>
        public long MessageBlockNumbers60sec
        {
            get { return ConnectHandle.ConnectHandle_MessageBlockNumbers60sec( m_Value ); }
        }

        /// <summary>
        /// 最后数据包的时间
        /// </summary>
        public long LastMessageBlockTime
        {
            get { return ConnectHandle.ConnectHandle_LastMessageBlockTime(m_Value); }
        }

        /// <summary>
        /// 数据包间隔的处理时间
        /// </summary>
        public long MessageBlockSpacingTime
        {
            get { return ConnectHandle.ConnectHandle_MessageBlockSpacingTime(m_Value); }
        }
        #endregion

        #region zh-CHS 共有方法 | en Public Methods
        /// <summary>
        /// 关闭连接
        /// </summary>
        public void CloseSocket()
        {
            ConnectHandle.ConnectHandle_CloseSocket(m_Value);
        }

        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="sendMessageBlock"></param>
        public void SendTo( MessageBlock sendMessageBlock )
        {
            ConnectHandle.ConnectHandle_SendTo( sendMessageBlock.Value, m_Value );
        }
        #endregion

        #region zh-CHS 内部属性 | en Internal Properties
        /// <summary>
        /// 客户段的句柄指针
        /// </summary>
        protected internal IntPtr Value
        {
            get { return m_Value; }
            set { m_Value = value; }
        }
        #endregion

        #region zh-CHS 引入DLL接口 | en DLL Import
        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern bool ConnectHandle_IsOnline(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern int ConnectHandle_RemotePort(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_FirstTime(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
        private static extern string ConnectHandle_RemoteOnlyIP(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_OnlineTime(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
        private static extern string ConnectHandle_ServerAddress( IntPtr pClientHandlerAtClient );

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_MessageBlockNumbers(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_MessageBlockNumbers60sec(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_LastMessageBlockTime(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        /// <returns></returns>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern long ConnectHandle_MessageBlockSpacingTime(IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pSendMessageBlock"></param>
        /// <param name="pClientHandlerAtClient"></param>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern void ConnectHandle_SendTo(IntPtr pSendMessageBlock, IntPtr pClientHandlerAtClient);

        /// <summary>
        /// dll 调用
        /// </summary>
        /// <param name="pClientHandlerAtClient"></param>
        [DllImport("Demo.Mmose.Net.dll", CallingConvention = CallingConvention.StdCall)]
        private static extern void ConnectHandle_CloseSocket(IntPtr pClientHandlerAtClient);
        #endregion
    }
}
#endregion

